<?php
////////////////////////////////////////////////////
//	LinBoard
//	Framework/Board.php
//	Created: 18th February 2009; 19:47 UTC
//	LinBoard (c) Copyright OpenInferno 2008, 2009
////////////////////////////////////////////////////

//Setup Environment
error_reporting(E_ALL | E_STRICT);

//Direct Access Check
if(!defined("LINBOARD"))
{
	die("<h1>Access Error</h1>Direct Access to this script is forbidden.");
}

class Board
{
	public function getAllBoards()
	{
		Framework::Mysql()->requireConnection();
		$result = Framework::Mysql()->query("SELECT * FROM `".Framework::Config()->Mysql['prefix']."boards` ORDER BY `order` ASC;");
		if(Framework::Mysql()->numRows($result) < 1)
		{
			return false;
		}
		
		$Boards = array();
		while($row = Framework::Mysql()->fetchArray($result))
		{
			$Boards["{$row['type']}"]['id'][] = $row['id'];
			$Boards["{$row['type']}"]['locked'][] = $row['locked'];
			$Boards["{$row['type']}"]['title'][] = $row['title'];
			$Boards["{$row['type']}"]['description'][] = $row['description'];
			$Boards["{$row['type']}"]['order'][] = $row['order'];
			$Boards["{$row['type']}"]['parent'][] = $row['parent'];
			$Boards["{$row['type']}"]['threads'][] = $row['threads'];
			$Boards["{$row['type']}"]['posts'][] = $row['posts'];
		}
		
		return $Boards;
	}
	
	public function getBoard($bid)
	{
		Framework::Mysql()->requireConnection();
		
		if(isset($bid) && is_numeric($bid))
		{
			$bid = (int)$bid;
		} else {
			return false;
		}
		
		$result = Framework::Mysql()->query("SELECT * FROM `".Framework::Config()->Mysql['prefix']."boards` WHERE `id` = '{$bid}' LIMIT 1;");
		if(Framework::Mysql()->numRows($result) < 1)
		{
			return false;
		}
		
		$Board = array();
		
		$row = Framework::Mysql()->fetchArray($result);
		
		$Board['id'] = $row['id'];
		$Board['locked'] = $row['locked'];
		$Board['title'] = $row['title'];
		$Board['description'] = $row['description'];
		$Board['order'] = $row['order'];
		$Board['parent'] = $row['parent'];
		$Board['threads'] = $row['threads'];
		$Board['posts'] = $row['posts'];
		
		return $Board;
	}
	
	public static function getInstance()
	{
		static $instance;
		if(!isset($instance))
		{
			$class = __CLASS__;
			$instance = new $class;
		}
		return $instance;
	}
	
}

?>